package com.jstide.credit.data.service.biz;

import cn.hutool.core.date.DateUtil;
import cn.hutool.db.Entity;
import com.jstide.credit.data.service.Algorithm;
import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.ResultSet;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class Factor24 extends Algorithm {

    private static final Logger logger = LoggerFactory.getLogger(Factor24.class);

    @Getter
    public final  String name="24";

    //失信被执行人名单
    //存在且移出日期为空，-100分；移出日期3年内-80分；移出日期3年外5年内，-20分；移出日期5年外不-分
    //有/无；按移出时间判断
    //-100
    @Getter
    public  final String sql =" select YCRQ from ZRRSXBZXRMDXX  where  join_id=@joinId  order by YCRQ desc nulls first  ";

    @Override
    public int translate(String rs) {
        return 0;
    }



    @Override
    public int translate(List<Entity> rs) {
        int score = 0;
        if(null!=rs && rs.size()>0){
            try {
                List<Date> dateList = rs.stream()
                        .map(k -> k.getDate("YCRQ"))
                        .collect(Collectors.toList());
               for(Date date : dateList){
                    if(null!=date) {
                        int year = DateUtil.ageOfNow(date);
                        if(year<3){
                            return -80;
                        }
                        else if(year>=3 && year<5){
                            return -20;
                        }
                    }
                    else{
                        return  -100;
                    }
               }

            }catch (Exception e){
                score=0;
            }
        }
        return score;
    }
}
